package com.wc5818.common;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * @author yqb
 * 
 */
public class BaseTools {

	/***
	 * 空的字符串 NULL
	 */
	public static String EMPTY = "NULL";

	/**
	 * 空字符串 ""
	 */
	public static String EMPTYSTRING = "";

	/**
	 * 生成14位订单号
	 * 
	 * @return
	 */
	public static String getRandomForOrderNum() {

		SimpleDateFormat sfDate = new SimpleDateFormat("yyMMddHHmmss");
		String strDate = sfDate.format(new Date());

		return strDate;

	}
	
	

	/**
	 * md5加密
	 * 
	 * @param md5
	 * @return
	 */
	public static String getMD5(String md5) {

		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("SHA");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		md.update(md5.getBytes());
		String str = new BigInteger(md.digest()).toString(32);
		return str;

	}

	/****
	 * 获取当前时间时间戳
	 * 
	 * @return
	 */
	public static long getCurrentTimeMillis() {

		return System.currentTimeMillis();

	}

	/***
	 * 生成随机码 6位或8位
	 * 
	 * @param num
	 * @return
	 */
	public static long getRandomNum(int num) {
		int n = 0;
		if (6 == num)
			n = 100000;
		if (8 == num)
			n = 10000000;

		return ((long) ((Math.random() * 9 + 1) * n));

	}

}
